//
//  DrawViewController.m
//  RealEstateQa
//
//  Created by 张立彬 on 13-7-9.
//  Copyright (c) 2013年 com.rong360. All rights reserved.
//

#import "DrawView.h"
#import "RealEstateQaViewController.h"

@implementation DrawView

//画制视图
-(void)DrawView:(UIView *)wrap
//标题
title:(NSString *)title
//描述
desc:(NSString *)desc
//表格
table:(UITableView *)table
//qa表格
qa:(UITableView *)qa

{
    CGRect _frame = [UIScreen mainScreen].applicationFrame;
    UIScrollView *s = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, _frame.size.height - 40)];
    ScrollBody = s;
    s.pagingEnabled = YES;
    //出现拖动缓冲效果
    s.bounces = YES;
    //s.backgroundColor = [UIColor blueColor];
    s.showsVerticalScrollIndicator = NO;
    s.showsHorizontalScrollIndicator = NO;
    //[s setContentSize:CGSizeMake(320,_frame.size.height + 30)];
    //[s setContentSize:CGSizeMake(320,700 + 30)];
    //s.delegate = self;
    [wrap addSubview:s];
    
    //加载步骤说明
    [self loadDesc:s title: title desc: desc];
    
    //加载表格数据
    //RealEstateQaViewController *Rc = [[RealEstateQaViewController alloc] init];
    //tableview.delegate = Rc.self;
    [s addSubview:table];
    [s addSubview:qa];
}

//加载步骤说明
-(void)loadDesc:(UIScrollView *)wrap title:(NSString *)title desc:(NSString *)desc{
    //加载标题
    UILabel *LabTitle = [[UILabel alloc] initWithFrame: CGRectMake(10, 10, 300, 20)];
    //设置字体
    [LabTitle setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
    LabTitle.lineBreakMode = NSLineBreakByWordWrapping;
    LabTitle.numberOfLines = 0; 
        
    CGRect currentFrame = LabTitle.frame;
    CGSize max = CGSizeMake(LabTitle.frame.size.width, 9999);
    CGSize expected = [title sizeWithFont:LabTitle.font constrainedToSize:max lineBreakMode:LabTitle.lineBreakMode];
    currentFrame.size.height = expected.height+5;
    LabTitle.frame = currentFrame;
    
    //设置背景为透明
    [LabTitle setBackgroundColor:[UIColor clearColor]];
    //写入文本
    [LabTitle setText:title];
    
    //追加进容器
    [wrap addSubview:LabTitle];
    
    //加载说明
    //加载标题
    int top = LabTitle.frame.size.height + LabTitle.frame.origin.y;
    UITextView *TextDesc = [[UITextView alloc] initWithFrame: CGRectMake(10, top, 300, IOS7_OR_LATER?60:10)];//changed by tian 14/3/27
    
    //设置字体
    [TextDesc setFont:[UIFont fontWithName:@"Helvetica" size:14]];
    //设置背景为透明
    [TextDesc setBackgroundColor:[UIColor clearColor]];
    //写入文本
    [TextDesc setText:desc];
    TextDesc.textColor = [UIColor colorWithRed:(102/255.0) green:(102/255.0) blue:(102/255.0) alpha:1];
    
    //设置不可编辑
    [TextDesc setEditable:NO];
    //设置不可滚动
    [TextDesc setScrollEnabled:NO];
    
    //追加进容器
    [wrap addSubview:TextDesc];
    
    //动太更新调试
    CGRect frame;
    frame = TextDesc.frame;
    frame.size.height = [TextDesc contentSize].height;
    TextDesc.frame = frame;
}

//同步高度
-(void)syncHeight{
    CGFloat scrollViewHeight = 0.0f;
    for (UIView* view in ScrollBody.subviews)
    {
        scrollViewHeight += view.frame.size.height;
    }
    
    [ScrollBody setContentSize:(CGSizeMake(320, scrollViewHeight+70))];
}

//画标题栏
-(void)titleBar:(UIView *)wrap title:(NSString *)title btn:(UIButton *)btn btnText:(NSString *)btnText tap:(NSString *)tap
{
    
    UIView *foo = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    foo.backgroundColor = [UIColor colorWithRed:(26/255.0) green:(173/255.0) blue:(242/255.0) alpha:1];
    [wrap addSubview:foo];
    
    //加载标题
    //创建uilabel
    UILabel *_title = [[UILabel alloc] initWithFrame:CGRectMake(110, 6, 100, 30)];

    //设置背景色
    _title.backgroundColor = [UIColor clearColor];
    
    //设置tag
    //label1.tag = 91;
    
    //设置标签文本
    _title.text = title;
    //设置标签文本字体和字体大小
    _title.font = [UIFont fontWithName:@"Helvetica" size:22];
    _title.textAlignment = 1;
    //文本颜色
    _title.textColor = [UIColor whiteColor];
    
    [foo addSubview:_title];
    
    //加载完成按钮
    //UIButton *returnHome = btn;
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(245, 6, 73, 33);
    [btn setTitle:btnText forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    //[returnHome addTarget:wrap.self action:@selector(tap) forControlEvents:UIControlEventTouchUpInside];
    
    [foo addSubview:btn];
    
}

//画图像s
-(void)image:(UIView *)wrap style:(NSString *)style src:(NSString *)src
{
    UIImageView *img= [[UIImageView alloc]initWithFrame:CGRectFromString(style)];
    [img setImage:[UIImage imageNamed:src]];
    [wrap addSubview:img];
}

//画标签
-(void)label:(UIView *)wrap style:(NSString *)style text:(NSString *)text
{
    //加载标题
    UILabel *label = [[UILabel alloc] initWithFrame: CGRectFromString(style)];
    //设置字体
    [label setFont:[UIFont fontWithName:@"Helvetica" size:18]];
    //设置背景为透明
    [label setBackgroundColor:[UIColor clearColor]];
    //写入文本
    [label setText:text];
    
    //追加进容器
    [wrap addSubview:label];
}

//画表格
-(void)tr:(UITableViewCell *)wrap text:(NSString *)text select:(NSString *)select tail:(NSString *)tail
{
    //设置字体
    [wrap.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:18]];
    wrap.textLabel.text=text;//设置文字
    
    wrap.textLabel.highlightedTextColor = [UIColor blackColor];
    
    UIView *bgColorView = [[UIView alloc] init];
    bgColorView.backgroundColor = [UIColor colorWithRed:(228/255.0) green:(236/255.0) blue:(241/255.0) alpha:1];
    [wrap setSelectedBackgroundView:bgColorView];
    [wrap setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    if(tail != nil && ![tail isEqual: @""]){
        //[wrap.contentView addSubview:tail];
        [self label:wrap.contentView style:@"{{280,5},{50,30}}" text:tail];
        [wrap setAccessoryType:UITableViewCellAccessoryNone];
    }
}

//画表格丰富
-(void)trRich:(UITableViewCell *)wrap icon:(UIImage *)icon text:(NSString *)text select:(NSString *)select detail:(NSString *)detail
{
    //设置icon
    wrap.imageView.image = icon;
    wrap.imageView.transform = CGAffineTransformMakeScale(0.5, 0.5);
    
    //设置标题文字
    [wrap.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:18]];
    wrap.textLabel.text=text;
    wrap.textLabel.highlightedTextColor = [UIColor blackColor];
    
    //设置描述文案
    wrap.detailTextLabel.text = detail;
    wrap.detailTextLabel.highlightedTextColor = [UIColor blackColor];
    
    //设置点击后背景
    UIView *bgColorView = [[UIView alloc] init];
    bgColorView.backgroundColor = [UIColor colorWithRed:(228/255.0) green:(236/255.0) blue:(241/255.0) alpha:1];
    [wrap setSelectedBackgroundView:bgColorView];
    
    //设置右箭头为空
    [wrap setAccessoryType:UITableViewCellAccessoryNone];
}


@end
